package co.fitstart.mobile.web.controller.course;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.demo2do.core.wechat.web.interceptor.WechatJsConfig;

import co.fitstart.entity.course.round.CourseRound;
import co.fitstart.entity.user.User;
import co.fitstart.entity.user.inbody.InbodyRecord;
import co.fitstart.mobile.service.CourseRoundService;
import co.fitstart.mobile.service.UserService;
import co.fitstart.mobile.web.interceptor.MobileDetect;
import co.fitstart.mobile.web.interceptor.Router;
import co.fitstart.mobile.web.interceptor.WechatAuthority;
import co.fitstart.mobile.web.resolver.Secure;

/**
 * 
 * @author mohanlan
 *
 */
@Controller
@RequestMapping("/profile/courses/{courseId}/inbody-records")
public class CourseInbodyController {
    
    @Autowired
    private CourseRoundService courseRoundService;
    
    @Autowired
    private UserService userService;
    
    /**
     * 
     * @return
     */
    @RequestMapping("")
    @Router(targetUrl = "/required-wechat")
    @WechatAuthority
    @MobileDetect
    @WechatJsConfig
    public ModelAndView index(@Secure User user,
                              @PathVariable("courseId") Long courseRoundId) {
        
        ModelAndView modelAndView = new ModelAndView("/course/inbody/inbody-record-list");
        
        CourseRound courseRound = courseRoundService.loadCourseRound(courseRoundId);
        List<InbodyRecord> inbodyRecords = userService.listInbodyRecoreds(user, courseRound);
        
        modelAndView.addObject("inbodyRecords", inbodyRecords);
        modelAndView.addObject("courseRound", courseRound);

        
        return modelAndView;
    }
    
}
